package com.mocha.activities;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

import com.mocha.DB.DBManager;

public class MainActivity extends FragmentActivity {
	DBManager manager = null;
	private int pageCount = 3;
	
	public final static int FRAGMENT_PAGE_CATEGORY_SELECT	 = 0;
	public final static int FRAGMENT_PAGE_CALENDAR_MAIN		 = 1;
	public final static int FRAGMENT_PAGE_QUICK_ADD			 = 2;
	
	ViewPager viewPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		viewPager = (ViewPager) findViewById(R.id.viewPager);
		viewPager.setAdapter(new SectionsPagerAdapter(getSupportFragmentManager()));
		viewPager.setCurrentItem(FRAGMENT_PAGE_CALENDAR_MAIN);
		
		DBManager.getInstance(this);
	}
	
	private class SectionsPagerAdapter extends FragmentPagerAdapter{
		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			// TODO Auto-generated method stub
			switch(position){
			case FRAGMENT_PAGE_CATEGORY_SELECT:
				return new CategorySelectActivity();
			case FRAGMENT_PAGE_CALENDAR_MAIN:
				return new CalendarMainActivity();
			case FRAGMENT_PAGE_QUICK_ADD:
				return new QuickAddActivity();
			default:
				return null;
			}
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return pageCount;
		}
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
